# -*- coding: utf-8 -*-
class Inventory < ActiveRecord::Base
  has_many :inventory_details ,:dependent => :destroy  #级联删除子表

  belongs_to :employee
  belongs_to :vendor

  belongs_to :warehouse
  belongs_to :department
  belongs_to :company
  belongs_to :auditor, :class_name => 'Employee', :foreign_key => 'auditor_id'

  def self.findAllInventories conditionsStr,conditionsHash,paramsHash
    find(
      :all,
      :conditions => [conditionsStr,conditionsHash],
      :include=> [:inventory_details],
      :offset => paramsHash[:offset],
      :limit => paramsHash[:limit],
      :order => 'inventories.updated_at DESC'
    )
  end

  def self.countAllInventories conditionsStr,conditionsHash
    count(
      :all,
      :include=> [:inventory_details],
      :conditions => [conditionsStr,conditionsHash]
    )
  end
end
